package org.lvgo.jx3.furniture.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.lvgo.jx3.common.LvgoResult;
import org.lvgo.jx3.furniture.entity.FurnitureInfo;
import org.lvgo.jx3.furniture.service.IFurnitureInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 家具访问
 *
 * @author lvgorice@gmail.com
 * @version 1.0
 * @date 2020/6/17 9:32
 */
@CrossOrigin
@RestController
@RequestMapping("/api/furniture")
public class FurnitureInfoController {

    @Resource
    private IFurnitureInfoService furnitureInfoService;

    /**
     * 获取全部家具列表
     *
     * @param current 当前页
     * @param size    每页记录数
     * @param name    家具名称
     * @param level   品质
     * @param order   排序规则
     * @param source  来源
     * @return 家具列表
     *
     */
    @RequestMapping(method = RequestMethod.GET)
    public LvgoResult getFurnitureList(int current, int size, String name, Integer level, int order, Integer source) {
        Page<FurnitureInfo> list = furnitureInfoService.getFurnitureList(current, size, name, level, order, source);
        return LvgoResult.result(list);
    }

    /**
     * 根据类型获取家具列表
     *
     * @param type    家具类别
     * @param current 当前页
     * @param size    每页记录数
     * @param name    家具名称
     * @param level   品质
     * @param order   排序规则
     * @param source  来源
     * @return 家具列表
     */
    @RequestMapping(value = "/category/{type}", method = RequestMethod.GET)
    public LvgoResult getFurnitureByCategory(@PathVariable("type") Integer type, int current, int size, String name, Integer level, int order, Integer source) {
        Page<FurnitureInfo> list = furnitureInfoService.getFurnitureListByCategory(type, current, size, name, level, order, source);
        return LvgoResult.result(list);
    }


    /**
     * 家具类别列表
     *
     * @return 家具类别列表
     */
    @RequestMapping(value = "/categories", method = RequestMethod.GET)
    public LvgoResult getFurnitureCategories() {
        List<Map<String, Object>> categories = furnitureInfoService.getFurnitureCategories();
        return LvgoResult.result(categories);
    }

    /**
     * 家具副本列表
     *
     * @return 家具类别列表
     */
    @RequestMapping(value = "/sourceOptions", method = RequestMethod.GET)
    public LvgoResult getFurnitureSourceOptions() {
        List<Map<String, Object>> categories = furnitureInfoService.getFurnitureSourceOptions();
        return LvgoResult.result(categories);
    }

    /**
     * 家具副本列表
     *
     * @return 家具类别列表
     */
    @RequestMapping(value = "/sources", method = RequestMethod.GET)
    public LvgoResult getFurnitureSources() {
        List<Map<String, Object>> categories = furnitureInfoService.getFurnitureSources();
        return LvgoResult.result(categories);
    }
}
